package com.example.demo.business.controller.v1;

import com.example.demo.business.bean.vo.StarItemVo;
import com.example.demo.business.dao.HStarDao;
import com.example.demo.business.service.StarService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("v1")
public class StarController {

    @Autowired
    private HStarDao hStarDao;

    @Autowired
    private StarService starService;
    @GetMapping("/star/list")
    public Object getStarList(Pageable pageable,String searchKey){
//        0就是全部
        if ("0".equals(searchKey)){
            return hStarDao.findAll(pageable).map(item->{
                //TODO 每个女友都要判断一下用户是否收藏
                StarItemVo starItemVo = new StarItemVo();
                BeanUtils.copyProperties(item,starItemVo);
                starItemVo.setIds(item.getId());
                return starItemVo;
            }).getContent();
        }else {
            return hStarDao.findByPinyinName(searchKey,pageable).map(item->{
                StarItemVo starItemVo = new StarItemVo();
                BeanUtils.copyProperties(item,starItemVo);
                starItemVo.setIds(item.getId());
                return starItemVo;
            }).getContent();
        }
    }

    //查看女友详情
    @GetMapping("/star/detail")
    public Object getStarDetail(String token,int starId,Pageable pageable){
        return starService.getStarDetail(token,starId,pageable);
    }


}
